package znbkBkfx;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.znbk.znbklibrary.base.BaseLongActivity;
import com.example.znbk.znbklibrary.dialog.LoadingDialog;
import com.example.znbk.znbklibrary.widget.ControlScrollViewPager;
import com.google.gson.Gson;
import com.lancoo.znbkxx.R;
import com.lancoo.znbkxx.beans.UserInfoBean;
import com.lancoo.znbkxx.net.URLConstant;
import com.lancoo.znbkxx.uis.PhoneMainActivity;
import com.example.znbk.znbklibrary.base.AnswerViewPagerAdapter;
import com.example.znbk.znbklibrary.base.BaseFragment;
import com.example.znbk.znbklibrary.base.BaseFragmentPagerAdapter;
import com.example.znbk.znbklibrary.dialog.ExitDialog;
import com.example.znbk.znbklibrary.dialog.PauseDialog;
import com.example.znbk.znbklibrary.util.LancooUtils;
import com.example.znbk.znbklibrary.util.TimeUtils;
import com.example.znbk.znbklibrary.widget.ScaleButton;
import com.tt.SkEgnManager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import znbkBkfx.AboutCountDowm.CountDownView;
import znbkBkfx.AboutKnowledgePoint.HighLightKeyWordUtil;
import znbkBkfx.BKFX_PPT.BkfxPptAnswerAdapter;
import znbkBkfx.BKFX_PPT.BkfxPptFragment;
import znbkBkfx.BKFX_GCT.BkfxGctFragment;
import znbkBkfx.BKFX_TKT.BkfxTktAnswerAdapter;
import znbkBkfx.BKFX_TKT.BkfxTktFragment;
import znbkBkfx.BKFX_TLTK.BkfxTltkAnswerAdapter;
import znbkBkfx.BKFX_TLTK.BkfxTltkFragment;
import znbkBkfx.BKFX_TLXZ.BkfxTlxzAnswerAdapter;
import znbkBkfx.BKFX_TLXZ.BkfxTlxzFragment;
import znbkBkfx.BKFX_WXXZ.BkfxWxxzFragment;
import znbkBkfx.BKFX_YDJD.BkfxYdjdAnswerAdapter;
import znbkBkfx.BKFX_YDJD.BkfxYdjdFragment;
import znbkBkfx.BKFX_YDXZ.BkfxYdxzAnswerAdapter;
import znbkBkfx.BKFX_YDXZ.BkfxYdxzFragment;
import znbkBkfx.BKFX_YDZH.BkfxYdzhAnswerAdapter_jd;
import znbkBkfx.BKFX_YDZH.BkfxYdzhAnswerAdapter_tk;
import znbkBkfx.BKFX_YDZH.BkfxYdzhFragment;
import znbkBkfx.BKFX_ZW.BkfxZwFragment;
import znbkBkfx.BkFX_DXT.BkfxDxtAnswerAdapter;
import znbkBkfx.BkFX_DXT.BkfxDxtFragment;
import znbkBkfx.BkfxAnswerSheet.NewShowAnswerSheetDialog;
import znbkBkfx.BkfxResultAnalysis.BkfxPaperResultActivity;
import znbkBkfx.GetBkfxJson.BkfxPaperEntity;
import znbkBkfx.PostCollectionJson.PostCollectionJson;
import znbkBkfx.PostCollectionJson.PostCollection_interface;
import znbkBkfx.PostSaveItemQues.ItemAnswerModel;
import znbkBkfx.PostSaveItemQues.PostSaveItemQuesAnswer_interface;
import znbkBkfx.PostSaveSubjectiveQues.PostSaveSubjectiveItemQuesAnswer_interface;
import znbkBkfx.PostSaveSubjectiveQues.ResultSubjectiveItemJson;
import znbkBkfx.PostSaveSubjectiveQues.SubjectiveItemAnswerModel;
import znbkBkfx.PostSubmitPaper.PostSubmitPaper_interface;

public class BkfxActivity extends BaseLongActivity {

    /*
     * 单选题     A
     * 听力填空   S
     * 词汇填空   N
     * 阅读填空   Q
     * 听力选择   E
     * 阅读选择   D
     * 完形选择   C
     * 改错题     U
     * 词汇匹配   m
     * 补全对话   b
     * 看图写句子 d
     * 阅读简答   X
     * 翻译题     g
     * 连词成句   V
     * 阅读综合   k
     * 作文       f
     * */

    @Override
    protected int setLayout() {
        return R.layout.activity_bkfxpaper_new;
    }


    private int OldThisPageIndex = -1;
    private BkfxPaperEntity bkfxPaperEntity = null;
    private int currentPageIndex = 0;//记录当前试题页的地址页码
    private ScaleButton mSBtnBack;//返回按钮
    private ScaleButton mSBtnAnswerNote;//笔记
    private ScaleButton mSBtnAnswerCollection;//收藏
    private ScaleButton mSBtnAnswerSheet;//答题卡
    public static Chronometer mChronometerAnswerTime;//计时器
    private ProgressBar mPbQuesRate;//试题作答进度
    private TextView mTvGenreName;//试题题型

    public static ControlScrollViewPager mVpBkfx;//难题训练viewpager
    private List<BaseFragment> mFragmentList;
    private BaseFragmentPagerAdapter mBkfxAdapter;
    @Override
    protected void initView() {
        getBkfxPaperInfor();
        //初始化控件
        mSBtnBack = findViewById(R.id.sbtn_back);
        int State = bkfxPaperEntity.getState();
        if(State==2||State==3){
            mSBtnBack.setText("查看试题");
        }else{
            String PaperName = bkfxPaperEntity.getPaperName();
            mSBtnBack.setText(PaperName);
        }
        mSBtnAnswerNote = findViewById(R.id.sbtn_answerNote);
        mSBtnAnswerCollection = findViewById(R.id.sbtn_answerCollection);
        mSBtnAnswerSheet = findViewById(R.id.sbtn_answerSheet);
        mChronometerAnswerTime = findViewById(R.id.chronometer_answerTime);
        if(State==2||State==3){
            mSBtnAnswerSheet.setVisibility(View.GONE);
            mChronometerAnswerTime.setVisibility(View.GONE);
        }else {
            mSBtnAnswerSheet.setVisibility(View.VISIBLE);
            mChronometerAnswerTime.setVisibility(View.VISIBLE);
            int currentDutionTimeA = bkfxPaperEntity.getDuration();
            mChronometerAnswerTime.setBase(TimeUtils.convertStrTimeToLong(TimeUtils.secToTime(currentDutionTimeA)));
            mChronometerAnswerTime.start();
            Log.e("初始时间","=================初始时间=================="+Integer.valueOf(getChronometerSeconds(mChronometerAnswerTime)));
        }

        mPbQuesRate = findViewById(R.id.pb_quesRate);
        mTvGenreName = findViewById(R.id.tv_quesType);
        mVpBkfx = findViewById(R.id.vp_bkfx);

        doBusiness();
    }

    public void doBusiness() {
        /*处理业务操作*/
        clickBack();//处理返回按钮点击事件
        clickAnswerNote();//处理笔记按钮点击事件
        clickAnswerSheet();//处理答题卡按钮点击事件
        showCurrentStudyQuesInfor();//显示当前试题相关概要信息
        clickChronometerTime();//启动计时器
    }

    private void clickBack(){
        mSBtnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int State = bkfxPaperEntity.getState();
                if(State!=2&&State!=3) {
                    showExitDialog();
                }else{
                    finish();
                }
            }
        });
    }
    private void clickAnswerNote(){
        mSBtnAnswerNote.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e("==clickAnswerNote==","============answerNote===========");
            }
        });
    }
    private void clickAnswerSheet(){
        mSBtnAnswerSheet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NewShowAnswerSheetDialog mShowAnswerSheetDialog = new NewShowAnswerSheetDialog(BkfxActivity.this, bkfxPaperEntity);
                mShowAnswerSheetDialog.show();
            }
        });
    }
    private void chronometerClickAnim(){
        /*
         * 组合动画
         * */
        ObjectAnimator scalexShow =  ObjectAnimator.ofFloat(mChronometerAnswerTime,View.SCALE_X,1.0f,1.2f,1.0f);
        ObjectAnimator scaleYShow =  ObjectAnimator.ofFloat(mChronometerAnswerTime,View.SCALE_Y,1.0f,1.2f,1.0f);
        AnimatorSet setShow = new AnimatorSet();
        setShow.playTogether(scalexShow,scaleYShow);
        setShow.setDuration(300);
        setShow.start();
    }
    private int currentDurationTime = 0;
    public  static String getChronometerSeconds(Chronometer cmt) {
        /**
         *
         * @param cmt  Chronometer控件
         * @return 小时+分钟+秒数  的所有秒数
         */
        int totalss = 0;
        String string = cmt.getText().toString();
        if(string.length()==7){

            String[] split = string.split(":");
            String string2 = split[0];
            int hour = Integer.parseInt(string2);
            int Hours =hour*3600;
            String string3 = split[1];
            int min = Integer.parseInt(string3);
            int Mins =min*60;
            int  SS =Integer.parseInt(split[2]);
            totalss = Hours+Mins+SS;
            return String.valueOf(totalss);
        }

        else if(string.length()==5){

            String[] split = string.split(":");
            String string3 = split[0];
            int min = Integer.parseInt(string3);
            int Mins =min*60;
            int  SS =Integer.parseInt(split[1]);

            totalss =Mins+SS;
            return String.valueOf(totalss);
        }
        return String.valueOf(totalss);


    }
    private void clickChronometerTime(){
//        mChronometerAnswerTime.setBase(SystemClock.elapsedRealtime());//计时器清零
//        mChronometerAnswerTime.start();
        mChronometerAnswerTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                chronometerClickAnim();
                showChronometerTimePauseDialog();
            }
        });
        mChronometerAnswerTime.setOnChronometerTickListener(new Chronometer.OnChronometerTickListener() {
            @Override
            public void onChronometerTick(Chronometer chronometer) {
                //计时器绑定实时监听
            }
        });
    }

    @SuppressLint("NewApi")
    private void showCurrentStudyQuesInfor(){
        final int FinishCount = bkfxPaperEntity.getFinishCount();
        mPbQuesRate.setMax(pageSize);
        int State = bkfxPaperEntity.getState();
        if(State==2||State==3){
            int PaperAnswerSize = bkfxPaperEntity.getPaperAnswer().size();
            mPbQuesRate.setProgress(PaperAnswerSize, true);
        }else {
            mPbQuesRate.setProgress(FinishCount + 1, true);
        }
        String GenreName = bkfxPaperEntity.getQuesList().get(FinishCount).getGenreInfo().getGenreName();
        if(GenreName.equals("")){
            GenreName = bkfxPaperEntity.getQuesList().get(FinishCount).getTypeInfo().getTypeName();
        }

        int ThisPageIndex = -1;
        String QuesList_QuesID = bkfxPaperEntity.getQuesList().get(FinishCount).getQuesID();
        int PaperQues_size = bkfxPaperEntity.getPaperQues().size();
        for(int i=0;i<PaperQues_size;i++){
            int PaperQuesChild_size = bkfxPaperEntity.getPaperQues().get(i).getQuesList().size();
            for(int j=0;j<PaperQuesChild_size;j++){
                String PaperQues_QuesID = bkfxPaperEntity.getPaperQues().get(i).getQuesList().get(j).getQuesID();
                if(PaperQues_QuesID.equals(QuesList_QuesID)){
                    ThisPageIndex = i;
                    break;
                }
            }
        }
        mTvGenreName.setText(LancooUtils.numberToChinese(ThisPageIndex+1)+"、"+GenreName);
        OldThisPageIndex = ThisPageIndex;
        mFragmentList = new ArrayList<>();
        for(int i=0;i<pageSize;i++){
            String TypeNo = bkfxPaperEntity.getQuesList().get(i).getTypeInfo().getTypeNo();
            if(TypeNo.equals("f")) {
                int answerViewFlag = -1;
                String AudioPath = bkfxPaperEntity.getPaperAnswer().get(i).
                        getChildList().get(0).getSubChildList().get(0).getSubChildItem().get(0).getAudioPath();
                String ImagePath = bkfxPaperEntity.getPaperAnswer().get(i).
                        getChildList().get(0).getSubChildList().get(0).getSubChildItem().get(0).getImagePath();
                if(AudioPath.equals("")&ImagePath.equals("")){
                    answerViewFlag = 0;
                }else{
                    if(!AudioPath.equals("")){
                        answerViewFlag = 1;
                    }else if(!ImagePath.equals("")){
                        answerViewFlag = 2;
                    }
                }
                mFragmentList.add(new BkfxZwFragment(answerViewFlag,bkfxPaperEntity, i, new BkfxZwFragment.CallBackFragmentZw() {
                    @Override
                    public void pageMoveNext() {
                        if ((currentPageIndex + 1) < pageSize) {
                            mVpBkfx.setCurrentItem(currentPageIndex + 1);
                        } else {
                            showSubmitedDialog();
                        }
                    }

                    @Override
                    public void saveBkfx_ZwQuesAnswer() {
                        SaveBkfx_KgtQuesAnswer(currentPageIndex);
                        if ((currentPageIndex + 1) == pageSize) {
                            SubmitPaper();
                        }
                    }
                }));
            }else if(TypeNo.equals("k")){
                mFragmentList.add(new BkfxYdzhFragment(bkfxPaperEntity, i, new BkfxYdzhFragment.CallBackFragmentYdzh() {
                    @Override
                    public void pageMoveNext() {
                        if ((currentPageIndex + 1) < pageSize) {
                            mVpBkfx.setCurrentItem(currentPageIndex + 1);
                        } else {
                            Log.e("==mFragmentList==", "=========A===========没有更多题目了=============");
                            Toast.makeText(BkfxActivity.this, "没有更多题目了", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void saveSubjectiveItemQuesAnswer() {
                        SaveBkfx_ZgtQuesAnswer(currentPageIndex);
                    }
                }));
            }else if(TypeNo.equals("E")){
                mFragmentList.add(new BkfxTlxzFragment(bkfxPaperEntity, i, new BkfxTlxzFragment.CallBackFragmentTlxz() {
                    @Override
                    public void pageMoveNext() {
                        if ((currentPageIndex + 1) < pageSize) {
                            mVpBkfx.setCurrentItem(currentPageIndex + 1);
                        } else {
                            Log.e("==mFragmentList==", "=========A===========没有更多题目了=============");
                            Toast.makeText(BkfxActivity.this, "没有更多题目了", Toast.LENGTH_SHORT).show();
                        }
                    }
                }));
            }else if(TypeNo.equals("D")){
                mFragmentList.add(new BkfxYdxzFragment(bkfxPaperEntity, i, new BkfxYdxzFragment.CallBackFragmentYdxz() {
                    @Override
                    public void pageMoveNext() {
                        if ((currentPageIndex + 1) < pageSize) {
                            mVpBkfx.setCurrentItem(currentPageIndex + 1);
                        } else {
                            Log.e("==mFragmentList==", "=========A===========没有更多题目了=============");
                            Toast.makeText(BkfxActivity.this, "没有更多题目了", Toast.LENGTH_SHORT).show();
                        }
                    }
                }));
            }else if(TypeNo.equals("N")||TypeNo.equals("Q")){
                mFragmentList.add(new BkfxTktFragment(bkfxPaperEntity, i, new BkfxTktFragment.CallBackFragmentTkt() {
                    @Override
                    public void pageMoveNext() {
                        if ((currentPageIndex + 1) < pageSize) {
                            mVpBkfx.setCurrentItem(currentPageIndex + 1);
                        } else {
                            Log.e("==mFragmentList==", "=========A===========没有更多题目了=============");
                            Toast.makeText(BkfxActivity.this, "没有更多题目了", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void submitKgtQuesAnswer() {
                        SaveBkfx_KgtQuesAnswer(currentPageIndex);
                    }
                }));
            }else if(TypeNo.equals("U")){
                mFragmentList.add(new BkfxGctFragment(bkfxPaperEntity, i, new BkfxGctFragment.CallBackFragmentGct() {
                    @Override
                    public void pageMoveNext() {
                        if ((currentPageIndex + 1) < pageSize) {
                            mVpBkfx.setCurrentItem(currentPageIndex + 1);
                        } else {
                            Log.e("==mFragmentList==", "=========A===========没有更多题目了=============");
                            Toast.makeText(BkfxActivity.this, "没有更多题目了", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void saveItemQuesAnswer() {
                        SaveBkfx_KgtQuesAnswer(currentPageIndex);
                    }
                }));
            }else if(TypeNo.equals("S")){
                mFragmentList.add(new BkfxTltkFragment(bkfxPaperEntity, i, new BkfxTltkFragment.CallBackFragmentTltk() {
                    @Override
                    public void pageMoveNext() {
                        if ((currentPageIndex + 1) < pageSize) {
                            mVpBkfx.setCurrentItem(currentPageIndex + 1);
                        } else {
                            Log.e("==mFragmentList==", "=========A===========没有更多题目了=============");
                            Toast.makeText(BkfxActivity.this, "没有更多题目了", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void submitKgtQuesAnswer() {
                        SaveBkfx_KgtQuesAnswer(currentPageIndex);
                    }
                }));
            }else if(TypeNo.equals("C")){
                mFragmentList.add(new BkfxWxxzFragment(bkfxPaperEntity, i, new BkfxWxxzFragment.CallBackFragmentWxxz() {
                    @Override
                    public void pageMoveNext() {
                        if ((currentPageIndex + 1) < pageSize) {
                            mVpBkfx.setCurrentItem(currentPageIndex + 1);
                        } else {
                            Log.e("==mFragmentList==", "=========A===========没有更多题目了=============");
                            Toast.makeText(BkfxActivity.this, "没有更多题目了", Toast.LENGTH_SHORT).show();
                        }
                    }
                }));
            }else if(TypeNo.equals("m")){
                mFragmentList.add(new BkfxPptFragment(bkfxPaperEntity, i, new BkfxPptFragment.CallBackFragmentPpt() {
                    @Override
                    public void pageMoveNext() {
                        if ((currentPageIndex + 1) < pageSize) {
                            mVpBkfx.setCurrentItem(currentPageIndex + 1);
                        } else {
                            Log.e("==mFragmentList==", "=========A===========没有更多题目了=============");
                            Toast.makeText(BkfxActivity.this, "没有更多题目了", Toast.LENGTH_SHORT).show();
                        }
                    }
                }));
            }else if(TypeNo.equals("b")||TypeNo.equals("d")||TypeNo.equals("X")||TypeNo.equals("g")||TypeNo.equals("V")){
                mFragmentList.add(new BkfxYdjdFragment(bkfxPaperEntity, i, new BkfxYdjdFragment.CallBackFragmentYdjd() {
                    @Override
                    public void pageMoveNext() {
                        if ((currentPageIndex + 1) < pageSize) {
                            mVpBkfx.setCurrentItem(currentPageIndex + 1);
                        } else {
                            Log.e("==mFragmentList==", "=========A===========没有更多题目了=============");
                            Toast.makeText(BkfxActivity.this, "没有更多题目了", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void saveSubjectiveItemQuesAnswer() {
//                        String TypeNoA = bkfxPaperEntity.getQuesList().get(currentPageIndex).getTypeInfo().getTypeNo();
//                        if(!TypeNoA.equals("V")) {
//                            SaveSubjectiveItemQuesAnswer(currentPageIndex);
//                        }
                        SaveBkfx_ZgtQuesAnswer(currentPageIndex);
                    }
                }));
            }else if(TypeNo.equals("A")){
                mFragmentList.add(new BkfxDxtFragment(bkfxPaperEntity, i, new BkfxDxtFragment.CallBackFragmentDxt() {
                    @Override
                    public void pageMoveNext() {
                        if ((currentPageIndex + 1) < pageSize) {
                            mVpBkfx.setCurrentItem(currentPageIndex + 1);
                        } else {
                            Log.e("==mFragmentList==", "=========A===========没有更多题目了=============");
                            Toast.makeText(BkfxActivity.this, "没有更多题目了", Toast.LENGTH_SHORT).show();
                        }
                    }
                }));
            }

        }
        mBkfxAdapter = new BaseFragmentPagerAdapter(getSupportFragmentManager(), mFragmentList);
        mVpBkfx.setAdapter(mBkfxAdapter);

        mVpBkfx.setCurrentItem(FinishCount);
        showCollectionInfor(FinishCount);
        mVpBkfx.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int position) {

                mVpBkfx.setScrollble(false);
                final Handler mH = new Handler();
                mH.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mVpBkfx.setScrollble(true);
                        mH.removeCallbacks(this);
                    }
                },800);

                Log.e("onPageSelected","===========currentPageIndex=======当前==========="+currentPageIndex);
                Log.e("onPageSelected","===========position=======当前==========="+position);
                showCollectionInfor(position);

                int SubmitState = bkfxPaperEntity.getPaperAnswer().get(position-1).getSubmitState();
                int State = bkfxPaperEntity.getState();
                if(State!=2&&State!=3&&SubmitState!=2) {
                    if (currentPageIndex >= FinishCount) {
                        if (currentPageIndex < position) {
                            Log.e("onPageSelected","===========currentPageIndex=======可保存===========");
                            String TypeNo = bkfxPaperEntity.getQuesList().get(currentPageIndex).getTypeInfo().getTypeNo();
                            if(TypeNo.equals("D")) {
                                SaveBkfx_KgtQuesAnswer(currentPageIndex);//测试完成。。。。。
                            }else if(TypeNo.equals("C")){
                                SaveBkfx_KgtQuesAnswer(currentPageIndex);//测试完成。。。。。
                            }else if(TypeNo.equals("E")){
                                SaveBkfx_KgtQuesAnswer(currentPageIndex);//测试完成。。。。。
                            }else if(TypeNo.equals("A")){
                                SaveBkfx_KgtQuesAnswer(currentPageIndex);//测试完成。。。。。
                            }else if(TypeNo.equals("m")){
                                SaveBkfx_KgtQuesAnswer(currentPageIndex);//测试中。。。。。
                            }else if(TypeNo.equals("N")||TypeNo.equals("Q")){
                                SaveBkfx_KgtQuesAnswer(currentPageIndex);//测试中。。。。。
                            }else if(TypeNo.equals("S")){
                                SaveBkfx_KgtQuesAnswer(currentPageIndex);//测试中。。。。。
                            }else if(TypeNo.equals("U")){
                                SaveBkfx_KgtQuesAnswer(currentPageIndex);//测试中。。。。。
                            }else if(TypeNo.equals("f")){
                                SaveBkfx_ZgtQuesAnswer(currentPageIndex);//测试中。。。。。
                            }else if(TypeNo.equals("V")){
                                SaveBkfx_ZgtQuesAnswer(currentPageIndex);//测试中。。。。。
                            }else if(TypeNo.equals("X")){
                                SaveBkfx_ZgtQuesAnswer(currentPageIndex);//测试中。。。。。
                            }else if(TypeNo.equals("b")){
                                SaveBkfx_ZgtQuesAnswer(currentPageIndex);//测试中。。。。。
                            }else if(TypeNo.equals("d")){
                                SaveBkfx_ZgtQuesAnswer(currentPageIndex);//测试中。。。。。
                            }else if(TypeNo.equals("g")){
                                SaveBkfx_ZgtQuesAnswer(currentPageIndex);//测试中。。。。。
                            }else if(TypeNo.equals("k")){
                                SaveBkfx_ZgtQuesAnswer(currentPageIndex);//测试中。。。。。
                            }
                            mPbQuesRate.setProgress(position + 1, true);

                            int CurrentPaperDuration = Integer.valueOf(getChronometerSeconds(mChronometerAnswerTime));
                            bkfxPaperEntity.setDuration(CurrentPaperDuration);
                        }
                    }
                }

                String GenreName = bkfxPaperEntity.getQuesList().get(position).getGenreInfo().getGenreName();
                if(GenreName.equals("")){
                    GenreName = bkfxPaperEntity.getQuesList().get(position).getTypeInfo().getTypeName();
                }

                int ThisPageIndex = -1;
                String QuesList_QuesID = bkfxPaperEntity.getQuesList().get(position).getQuesID();
                int PaperQues_size = bkfxPaperEntity.getPaperQues().size();
                for(int i=0;i<PaperQues_size;i++){
                    int PaperQuesChild_size = bkfxPaperEntity.getPaperQues().get(i).getQuesList().size();
                    for(int j=0;j<PaperQuesChild_size;j++){
                        String PaperQues_QuesID = bkfxPaperEntity.getPaperQues().get(i).getQuesList().get(j).getQuesID();
                        if(PaperQues_QuesID.equals(QuesList_QuesID)){
                            ThisPageIndex = i;
                            break;
                        }
                    }
                }

                if(ThisPageIndex!=OldThisPageIndex) {
                    textAnimFlyOut(mTvGenreName);
                    mTvGenreName.setText(LancooUtils.numberToChinese((ThisPageIndex+1))+"、"+GenreName);
                    textAnimFlyIn(mTvGenreName);
                }
                OldThisPageIndex = ThisPageIndex;

                if(position>currentPageIndex){
                    //刷新上一页作答界面详情
                    if(SubmitState!=2) {
                        bkfxPaperEntity.getPaperAnswer().get(currentPageIndex).setSubmitState(2);
                        String TypeNo = bkfxPaperEntity.getQuesList().get(currentPageIndex).getTypeInfo().getTypeNo();
                        if(TypeNo.equals("k")){
                            BkfxYdzhFragment fragment = (BkfxYdzhFragment) mFragmentList.get(currentPageIndex);
                            Button mBtnSubmit = fragment.getView().findViewById(R.id.btn_submit);
                            mBtnSubmit.setVisibility(View.GONE);
                            mLlJudegLoading[currentPageIndex] = fragment.getView().findViewById(R.id.ll_judgeLoading);
                            mLlJudegLoading[currentPageIndex].setVisibility(View.VISIBLE);

                        }else if(TypeNo.equals("b")||TypeNo.equals("d")||TypeNo.equals("X")
                                ||TypeNo.equals("g")||TypeNo.equals("V")){
                            BkfxYdjdFragment fragment = (BkfxYdjdFragment) mFragmentList.get(currentPageIndex);
                            Button mBtnSubmit = fragment.getView().findViewById(R.id.btn_submit);
                            mBtnSubmit.setVisibility(View.GONE);
                            mLlJudegLoading[currentPageIndex] = fragment.getView().findViewById(R.id.ll_judgeLoading);
                            mLlJudegLoading[currentPageIndex].setVisibility(View.VISIBLE);

                        }else if(TypeNo.equals("E")) {
                            BkfxTlxzFragment fragment = (BkfxTlxzFragment) mFragmentList.get(currentPageIndex);
                            fragment.pause();
                            RelativeLayout mRlMyBrowseBg = fragment.getView().findViewById(R.id.rl_myBrowseBg);
                            mRlMyBrowseBg.setVisibility(View.GONE);
                            RelativeLayout mRlMyRecordBg = fragment.getView().findViewById(R.id.rl_myRecordBg);
                            mRlMyRecordBg.setVisibility(View.GONE);
                            //显示听力原文
                            TextView mTvListenScript = fragment.getView().findViewById(R.id.tv_listenScript);
                            mTvListenScript.setVisibility(View.VISIBLE);
                            String ListenScript  = bkfxPaperEntity.getQuesList().get(currentPageIndex).getAudioList().get(0).getText();
                            CharSequence ListenScriptA = Html.fromHtml("听力原文<br><br>"+ListenScript);
                            int ImprotantZSDSize = bkfxPaperEntity.getQuesList().get(currentPageIndex).getImprotantZSD().size();
                            String[] keyword = new String[ImprotantZSDSize];
                            String[] keywordCode = new String[ImprotantZSDSize];
                            for(int i=0;i<ImprotantZSDSize;i++){
                                keyword[i] = bkfxPaperEntity.getQuesList().get(currentPageIndex).getImprotantZSD().get(i).getName();
                                keywordCode[i] = bkfxPaperEntity.getQuesList().get(currentPageIndex).getImprotantZSD().get(i).getCode();
                            }
                            SpannableString highlightText = HighLightKeyWordUtil.highlight(ListenScriptA.toString(), keyword, keywordCode,"#FF0000");
                            mTvListenScript.setText(highlightText);
                            mTvListenScript.setMovementMethod(LinkMovementMethod.getInstance());//设置可点击状态

                            //显示刷新作答结果
                            ArrayList<View> list = new ArrayList<>();
                            list.clear();
                            int totalItemCount = bkfxPaperEntity.getQuesList().get(currentPageIndex).getChildList().size();
                            for(int i=0;i<totalItemCount;i++) {
                                final RecyclerView mRvAnswer = new RecyclerView(BkfxActivity.this);
                                mRvAnswer.setLayoutManager(new LinearLayoutManager(BkfxActivity.this));//必须先设置LayoutManager
                                BkfxTlxzAnswerAdapter mAnswerAdapter = new BkfxTlxzAnswerAdapter(BkfxActivity.this,
                                        bkfxPaperEntity,currentPageIndex,i,new BkfxTlxzAnswerAdapter.CallBackAdapterTlxz() {
                                    @Override
                                    public void callHideRecordMiView() {
                                    }

                                    @Override
                                    public void callRefreshClickAnswer() {

                                    }

                                    @Override
                                    public void callShowListenScript() {

                                    }

                                    @Override
                                    public void callShowResultStuScore(double stuScore) {

                                    }

                                });
                                mRvAnswer.setAdapter(mAnswerAdapter);
                                list.add(mRvAnswer);
                            }
                            ViewPager mVpAnswer = fragment.getView().findViewById(R.id.vp_answerTlxz);
                            mVpAnswer.setAdapter(new AnswerViewPagerAdapter(list));
                            mVpAnswer.setCurrentItem( bkfxPaperEntity.getPaperAnswer().get(currentPageIndex).getCurrentSubChildAnswerIndex());

                        }else if(TypeNo.equals("D")){
                            BkfxYdxzFragment fragment = (BkfxYdxzFragment) mFragmentList.get(currentPageIndex);
                            //显示刷新作答结果
                            ArrayList<View> list = new ArrayList<>();
                            list.clear();
                            int totalItemCount = bkfxPaperEntity.getQuesList().get(currentPageIndex).getChildList().size();
                            for(int i=0;i<totalItemCount;i++) {
                                final RecyclerView mRvAnswer = new RecyclerView(BkfxActivity.this);
                                mRvAnswer.setLayoutManager(new LinearLayoutManager(BkfxActivity.this));//必须先设置LayoutManager
                                BkfxYdxzAnswerAdapter mAnswerAdapter = new BkfxYdxzAnswerAdapter(BkfxActivity.this,
                                        bkfxPaperEntity,currentPageIndex,i,new BkfxYdxzAnswerAdapter.CallBackAdapterYdxz(){
                                    @Override
                                    public void callHideRecordMiView() {
                                    }

                                    @Override
                                    public void callRefreshClickAnswer() {

                                    }

                                    @Override
                                    public void callShowResultStuScore(double stuScore) {

                                    }

                                });
                                mRvAnswer.setAdapter(mAnswerAdapter);
                                list.add(mRvAnswer);
                            }
                            ViewPager mVpAnswer = fragment.getView().findViewById(R.id.vp_answerYdxz);
                            mVpAnswer.setAdapter(new AnswerViewPagerAdapter(list));
                            mVpAnswer.setCurrentItem( bkfxPaperEntity.getPaperAnswer().get(currentPageIndex).getCurrentSubChildAnswerIndex());

                        }else if(TypeNo.equals("N")||TypeNo.equals("Q")){
                            BkfxTktFragment fragment = (BkfxTktFragment) mFragmentList.get(currentPageIndex);
                            ScaleButton mSBtnSubmit = fragment.getView().findViewById(R.id.sbtn_submit);
                            mSBtnSubmit.setVisibility(View.GONE);
                            //显示刷新作答结果
                            ArrayList<View> list = new ArrayList<>();
                            list.clear();
                            final RecyclerView mRvAnswer = new RecyclerView(BkfxActivity.this);
                            mRvAnswer.setLayoutManager(new LinearLayoutManager(BkfxActivity.this));//必须先设置LayoutManager
                            BkfxTktAnswerAdapter mAnswerAdapter = new BkfxTktAnswerAdapter(BkfxActivity.this,
                                    bkfxPaperEntity,currentPageIndex);
                            mRvAnswer.setAdapter(mAnswerAdapter);
                            list.add(mRvAnswer);
                            ViewPager mVpAnswer = fragment.getView().findViewById(R.id.vp_answerTkt);
                            mVpAnswer.setAdapter(new AnswerViewPagerAdapter(list));
                        }else if(TypeNo.equals("U")){

                            BkfxGctFragment fragment = (BkfxGctFragment) mFragmentList.get(currentPageIndex);

                            ScrollView mSvGctAnswer = fragment.getView().findViewById(R.id.sv_gctAnswer);
                            mSvGctAnswer.setOverScrollMode(android.view.View.OVER_SCROLL_NEVER);

                            LinearLayout mLlGctAnswer = fragment.getView().findViewById(R.id.ll_gctAnswer);
                            mLlGctAnswer.setVisibility(View.VISIBLE);

                            Button mSBtnSubmit = fragment.getView().findViewById(R.id.sbtn_submitGct);
                            mSBtnSubmit.setVisibility(View.GONE);

                        }else if(TypeNo.equals("S")){
                            BkfxTltkFragment fragment = (BkfxTltkFragment) mFragmentList.get(currentPageIndex);
                            ScaleButton mSBtnSubmit = fragment.getView().findViewById(R.id.sbtn_submit);
                            mSBtnSubmit.setVisibility(View.GONE);
                            fragment.pause();
                            RelativeLayout mRlMyBrowseBg = fragment.getView().findViewById(R.id.rl_myBrowseBg);
                            mRlMyBrowseBg.setVisibility(View.GONE);
                            RelativeLayout mRlControlView= fragment.getView().findViewById(R.id.rl_controlView);
                            mRlControlView.setVisibility(View.GONE);
                            //显示刷新作答结果
                            ArrayList<View> list = new ArrayList<>();
                            list.clear();
                            final RecyclerView mRvAnswer = new RecyclerView(BkfxActivity.this);
                            mRvAnswer.setLayoutManager(new LinearLayoutManager(BkfxActivity.this));//必须先设置LayoutManager
                            BkfxTltkAnswerAdapter mAnswerAdapter = new BkfxTltkAnswerAdapter(BkfxActivity.this,
                                    bkfxPaperEntity,currentPageIndex,true);
                            mRvAnswer.setAdapter(mAnswerAdapter);
                            list.add(mRvAnswer);
                            ViewPager mVpAnswer = fragment.getView().findViewById(R.id.vp_answerTltk);
                            mVpAnswer.setAdapter(new AnswerViewPagerAdapter(list));
                        }else if(TypeNo.equals("A")){

                            BkfxDxtFragment fragment = (BkfxDxtFragment) mFragmentList.get(currentPageIndex);
                            //显示刷新作答结果
                            ArrayList<View> list = new ArrayList<>();
                            list.clear();
                            final RecyclerView mRvAnswer = new RecyclerView(BkfxActivity.this);
                            mRvAnswer.setLayoutManager(new LinearLayoutManager(BkfxActivity.this));//必须先设置LayoutManager
                            BkfxDxtAnswerAdapter mAnswerAdapter = new BkfxDxtAnswerAdapter(BkfxActivity.this,
                                    bkfxPaperEntity,currentPageIndex,new BkfxDxtAnswerAdapter.CallBackAdapterDxt(){

                                @Override
                                public void callHideRecordMiView() {

                                }

                                @Override
                                public void callShowResultStuScore(double Score) {

                                }

                            });
                            mRvAnswer.setAdapter(mAnswerAdapter);
                            list.add(mRvAnswer);
                            ViewPager mVpAnswer = fragment.getView().findViewById(R.id.vp_answerDxt);
                            mVpAnswer.setAdapter(new AnswerViewPagerAdapter(list));
                        }else if(TypeNo.equals("m")){
                            BkfxPptFragment fragment = (BkfxPptFragment) mFragmentList.get(currentPageIndex);
                            //显示刷新作答结果
                            ArrayList<View> list = new ArrayList<>();
                            list.clear();
                            final RecyclerView mRvAnswer = new RecyclerView(BkfxActivity.this);
                            mRvAnswer.setLayoutManager(new LinearLayoutManager(BkfxActivity.this));//必须先设置LayoutManager
                            BkfxPptAnswerAdapter mAnswerAdapter = new BkfxPptAnswerAdapter(BkfxActivity.this,
                                    bkfxPaperEntity,currentPageIndex,new BkfxPptAnswerAdapter.CallBackAdapterPpt(){

                                @Override
                                public void callHideRecordMiView() {

                                }

                                @Override
                                public void callClickWhichIndex(String stuAnswer) {

                                }

                                @Override
                                public void callShowResultStuScore(double stuScore) {

                                }

                                @Override
                                public void callSetCurrentStuAnswer(String currentStuAnswer) {

                                }

                            });
                            mRvAnswer.setAdapter(mAnswerAdapter);
                            list.add(mRvAnswer);
                            ViewPager mVpAnswer = fragment.getView().findViewById(R.id.vp_answerPpt);
                            mVpAnswer.setAdapter(new AnswerViewPagerAdapter(list));
                        }
                    }

                }
                currentPageIndex = position;

                Log.e("currentPageIndex","=========================currentPageIndex============"+currentPageIndex);
                //作答完毕后开启播放器开关按钮
                int SubmitStateA  = bkfxPaperEntity.getPaperAnswer().get(currentPageIndex).getSubmitState();
                if(SubmitStateA==2) {
                    String TypeNo = bkfxPaperEntity.getQuesList().get(currentPageIndex).getTypeInfo().getTypeNo();
                    if(TypeNo.equals("E")) {
                        BkfxTlxzFragment fragment = (BkfxTlxzFragment) mFragmentList.get(currentPageIndex);
                        fragment.setBtnPlayClickAbleTrue();
                    }else if(TypeNo.equals("S")){
                        Log.e("currentPageIndex","=========000000000================currentPageIndex============");
                        BkfxTltkFragment fragment = (BkfxTltkFragment) mFragmentList.get(currentPageIndex);
                        fragment.setBtnPlayClickAbleTrue();
                    }
                }

            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }

    private void textAnimFlyOut(TextView mTv){
        ObjectAnimator translationX =  ObjectAnimator.ofFloat(mTv,View.TRANSLATION_X,0f,-400f);
        AnimatorSet setShow = new AnimatorSet();
        setShow.playTogether(translationX);
        setShow.setDuration(300);
        setShow.start();
    }
    private void textAnimFlyIn(TextView mTv){
        ObjectAnimator translationX =  ObjectAnimator.ofFloat(mTv,View.TRANSLATION_X,200f,0f);
        AnimatorSet setShow = new AnimatorSet();
        setShow.playTogether(translationX);
        setShow.setStartDelay(300);
        setShow.setDuration(150);
        setShow.start();

    }

    private boolean isShowViewPause = false;
    public void showChronometerTimePauseDialog(){
        //暂停界面一切动态事务
        String TypeNo = bkfxPaperEntity.getQuesList().get(currentPageIndex).getTypeInfo().getTypeNo();
        if(TypeNo.equals("E")) {
            BkfxTlxzFragment fragment = (BkfxTlxzFragment) mFragmentList.get(currentPageIndex);
            RelativeLayout mRlMyBrowseBg = fragment.getView().findViewById(R.id.rl_myBrowseBg);
            CountDownView mCdvMyBrowse =  fragment.getView().findViewById(R.id.cdv_myBrowse);
            if(mRlMyBrowseBg.getVisibility()==View.VISIBLE) {
                mCdvMyBrowse.pauseCountDown();
                Log.e("back","========mRlMyBrowseBg====00000==============");
            }else{
                if(!fragment.isVoicePlayingEnd){
                    fragment.pause();
                }
            }
        }else if(TypeNo.equals("S")){
            BkfxTltkFragment fragment = (BkfxTltkFragment) mFragmentList.get(currentPageIndex);
            RelativeLayout mRlMyBrowseBg = fragment.getView().findViewById(R.id.rl_myBrowseBg);
            CountDownView mCdvMyBrowse =  fragment.getView().findViewById(R.id.cdv_myBrowse);
            if(mRlMyBrowseBg.getVisibility()==View.VISIBLE) {
                mCdvMyBrowse.pauseCountDown();
                Log.e("back","========mRlMyBrowseBg====00000==AAAAA============");
            }else{
                if(!fragment.isVoicePlayingEnd){
                    fragment.pause();
                }
            }
        }

        //暂停计时
        mChronometerAnswerTime.stop();
        currentDurationTime = Integer.valueOf(getChronometerSeconds(mChronometerAnswerTime));
        //初始化显示弹窗
        isShowViewPause = true;
        PauseDialog.Builder mPauseDialog = new PauseDialog.Builder(this);
        mPauseDialog.setTitle("温馨提示")
                .setMessage("休息一下···")
                .setContinueButton("继续", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        //继续计时
                        mChronometerAnswerTime.setBase(TimeUtils.convertStrTimeToLong(TimeUtils.secToTime(currentDurationTime)));
                        mChronometerAnswerTime.start();

                        String TypeNo = bkfxPaperEntity.getQuesList().get(currentPageIndex).getTypeInfo().getTypeNo();
                        if(TypeNo.equals("E")) {
                            Log.e("back","========AAAAAAAAA=============返回back=====");
                            BkfxTlxzFragment fragment = (BkfxTlxzFragment) mFragmentList.get(currentPageIndex);
                            RelativeLayout mRlMyBrowseBg = fragment.getView().findViewById(R.id.rl_myBrowseBg);
                            CountDownView mCdvMyBrowse =  fragment.getView().findViewById(R.id.cdv_myBrowse);
                            if(mRlMyBrowseBg.getVisibility()==View.VISIBLE) {
                                mCdvMyBrowse.resumeCountDown();
                                Log.e("back","========mRlMyBrowseBg====2222222==============");
                            }else{
                                if(!fragment.isVoicePlayingEnd){
                                    Log.e("back","========mRlMyBrowseBg====333333333==============");
                                    fragment.play();
                                }
                            }
                        }else if(TypeNo.equals("S")) {
                            Log.e("back","========AAAAAAAAA=============返回back=====");
                            BkfxTltkFragment fragment = (BkfxTltkFragment) mFragmentList.get(currentPageIndex);
                            RelativeLayout mRlMyBrowseBg = fragment.getView().findViewById(R.id.rl_myBrowseBg);
                            CountDownView mCdvMyBrowse =  fragment.getView().findViewById(R.id.cdv_myBrowse);
                            if(mRlMyBrowseBg.getVisibility()==View.VISIBLE) {
                                mCdvMyBrowse.resumeCountDown();
                                Log.e("back","========mRlMyBrowseBg====2222222==============");
                            }else{
                                if(!fragment.isVoicePlayingEnd){
                                    Log.e("back","========mRlMyBrowseBg====333333333==============");
                                    fragment.play();
                                }
                            }
                        }
                        isShowViewPause = false;
                    }
                }).create().show();
    }

    /*
     * 执行home键和电源键回调流程
     * */
    public static boolean isNeedShowViewExit = true;
    @Override
    protected void onPause() {
        super.onPause();
        int State = bkfxPaperEntity.getState();
        if(State!=2&&State!=3) {
            if(!isShowViewExit&&!isShowViewPause) {
                Log.e("==跳转1==", "========onPause=============特殊暂停====="+isNeedShowViewExit);
                if(isNeedShowViewExit) {
                    showChronometerTimePauseDialog();
                }
            }
        }else{
            String TypeNo = bkfxPaperEntity.getQuesList().get(currentPageIndex).getTypeInfo().getTypeNo();
            if(TypeNo.equals("E")) {
                BkfxTlxzFragment fragment = (BkfxTlxzFragment) mFragmentList.get(currentPageIndex);
                fragment.pause();
            }else if(TypeNo.equals("S")){
                BkfxTltkFragment fragment = (BkfxTltkFragment) mFragmentList.get(currentPageIndex);
                fragment.pause();
            }
        }
    }


    @Override
    public void onBackPressed() {
        Log.e("back","========BBBBBBBBBBBB=============返回back=====");
        int State = bkfxPaperEntity.getState();
        if(State!=2&&State!=3) {
            showExitDialog();
        }else{
            finish();
        }
    }

    private boolean isShowViewExit = false;
    public void showExitDialog(){
        //暂停界面一切动态事务
        String TypeNo = bkfxPaperEntity.getQuesList().get(currentPageIndex).getTypeInfo().getTypeNo();
        if(TypeNo.equals("E")) {
            Log.e("back","========AAAAAAAAA=============返回back=====");
            BkfxTlxzFragment fragment = (BkfxTlxzFragment) mFragmentList.get(currentPageIndex);
            RelativeLayout mRlMyBrowseBg = fragment.getView().findViewById(R.id.rl_myBrowseBg);
            CountDownView mCdvMyBrowse =  fragment.getView().findViewById(R.id.cdv_myBrowse);
            if(mRlMyBrowseBg.getVisibility()==View.VISIBLE) {
                mCdvMyBrowse.pauseCountDown();
                Log.e("back","========mRlMyBrowseBg====00000==============");
            }else{
                if(!fragment.isVoicePlayingEnd){
                    fragment.pause();
                }
            }
        }else if(TypeNo.equals("S")){
            BkfxTltkFragment fragment = (BkfxTltkFragment) mFragmentList.get(currentPageIndex);
            RelativeLayout mRlMyBrowseBg = fragment.getView().findViewById(R.id.rl_myBrowseBg);
            CountDownView mCdvMyBrowse =  fragment.getView().findViewById(R.id.cdv_myBrowse);
            if(mRlMyBrowseBg.getVisibility()==View.VISIBLE) {
                mCdvMyBrowse.pauseCountDown();
                Log.e("back","========mRlMyBrowseBg====00000====BBBBB==========");
            }else{
                if(!fragment.isVoicePlayingEnd){
                    fragment.pause();
                }
            }
        }


        //暂停计时
        mChronometerAnswerTime.stop();
        currentDurationTime = Integer.valueOf(getChronometerSeconds(mChronometerAnswerTime));
        //初始化显示弹窗
        isShowViewExit = true;
        ExitDialog.Builder mExitDialog = new ExitDialog.Builder(this);
        mExitDialog.setTitle("温馨提示")
                .setMessage("是否要退出本次训练···")
                .setExitButton("退出训练", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        isSubmitOrExitAlready = true;
                        isShowViewExit = false;
                        dialog.dismiss();
                        finish();
                        startActivity(PhoneMainActivity.class);
                    }
                })
                .setContinueButton("继续训练", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        isShowViewExit = false;
                        dialog.dismiss();
                        //继续计时
                        mChronometerAnswerTime.setBase(TimeUtils.convertStrTimeToLong(TimeUtils.secToTime(currentDurationTime)));
                        mChronometerAnswerTime.start();

                        String TypeNo = bkfxPaperEntity.getQuesList().get(currentPageIndex).getTypeInfo().getTypeNo();
                        if(TypeNo.equals("E")) {
                            BkfxTlxzFragment fragment = (BkfxTlxzFragment) mFragmentList.get(currentPageIndex);
                            RelativeLayout mRlMyBrowseBg = fragment.getView().findViewById(R.id.rl_myBrowseBg);
                            CountDownView mCdvMyBrowse =  fragment.getView().findViewById(R.id.cdv_myBrowse);
                            if(mRlMyBrowseBg.getVisibility()==View.VISIBLE) {
                                mCdvMyBrowse.resumeCountDown();
                            }else{
                                if(!fragment.isVoicePlayingEnd){
                                    fragment.play();
                                }
                            }
                        }else if(TypeNo.equals("S")){
                            BkfxTltkFragment fragment = (BkfxTltkFragment) mFragmentList.get(currentPageIndex);
                            RelativeLayout mRlMyBrowseBg = fragment.getView().findViewById(R.id.rl_myBrowseBg);
                            CountDownView mCdvMyBrowse =  fragment.getView().findViewById(R.id.cdv_myBrowse);
                            if(mRlMyBrowseBg.getVisibility()==View.VISIBLE) {
                                mCdvMyBrowse.resumeCountDown();
                                Log.e("back","========mRlMyBrowseBg====2222222==============");
                            }else{
                                if(!fragment.isVoicePlayingEnd){
                                    Log.e("back","========mRlMyBrowseBg====333333333==============");
                                    fragment.play();
                                }
                            }
                        }

                    }
                }).create().show();
    }

    private boolean isSubmitOrExitAlready = false;
    private void showSubmitedDialog(){
        ExitDialog.Builder mExitDialog = new ExitDialog.Builder(this);
        mExitDialog.setTitle("温馨提示")
                .setMessage("本份试卷已作答完成")
                .setExitButton("返回", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        isSubmitOrExitAlready = true;
                        dialog.dismiss();
                        finish();
                        startActivity(PhoneMainActivity.class);
                    }
                })
                .setContinueButton("查看结果", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        isSubmitOrExitAlready = true;
                        isNeedShowViewExit = false;
                        finish();
                        startActivity(BkfxPaperResultActivity.class);
                    }
                }).create().show();
    }

    private LinearLayout[] mLlJudegLoading;
    private int pageSize = -1;
    public static String PaperId = "";
    private void getBkfxPaperInfor(){
        bkfxPaperEntity = BkfxMainInforActivity.bkfxPaperEntity;
        pageSize = bkfxPaperEntity.getQuesList().size();;//试题页个数
        mLlJudegLoading = new LinearLayout[pageSize];
        currentPageIndex = bkfxPaperEntity.getFinishCount();
        PaperId = bkfxPaperEntity.getPaperID();
    }


    private void showCollectionInfor(final int position){
        boolean IsFavourite = bkfxPaperEntity.getPaperAnswer().get(position).isIsFavourite();
        if(IsFavourite) {
            // 使用代码设置drawableleft
            Drawable drawable = getResources().getDrawable(R.mipmap.topbar_icon_collection_select);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(),drawable.getMinimumHeight());//这一步必须要做,否则不会显示.
            mSBtnAnswerCollection.setCompoundDrawables(drawable, null, null, null);
        }else{
            // 使用代码设置drawableleft
            Drawable drawable = getResources().getDrawable(R.mipmap.topbar_icon_collection_unselect);
            drawable.setBounds(0, 0, drawable.getMinimumWidth(),drawable.getMinimumHeight());//这一步必须要做,否则不会显示.
            mSBtnAnswerCollection.setCompoundDrawables(drawable, null, null, null);
        }
        mSBtnAnswerCollection.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean IsFavourite = bkfxPaperEntity.getPaperAnswer().get(position).isIsFavourite();
                if(IsFavourite){
                    Log.e("==resultAA==","============result==AAA====000000000000000000=========");
                    postCollection(position,0);
                    bkfxPaperEntity.getPaperAnswer().get(position).setIsFavourite(false);
                    Drawable drawable = getResources().getDrawable(R.mipmap.topbar_icon_collection_unselect);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(),drawable.getMinimumHeight());//这一步必须要做,否则不会显示.
                    mSBtnAnswerCollection.setCompoundDrawables(drawable, null, null, null);
                }else{
                    Log.e("==resultAA==","============result==AAA====111111111111111111111=========");
                    postCollection(position,1);
                    bkfxPaperEntity.getPaperAnswer().get(position).setIsFavourite(true);
                    Drawable drawable = getResources().getDrawable(R.mipmap.topbar_icon_collection_select);
                    drawable.setBounds(0, 0, drawable.getMinimumWidth(),drawable.getMinimumHeight());//这一步必须要做,否则不会显示.
                    mSBtnAnswerCollection.setCompoundDrawables(drawable, null, null, null);
                }
            }
        });
    }


    private void postCollection(int position,int collectionFlag) {

        String QuesBreaf = bkfxPaperEntity.getQuesList().get(position).getQuesBrief();
        String QuesID = bkfxPaperEntity.getQuesList().get(position).getQuesID();
        String TypeNo = bkfxPaperEntity.getQuesList().get(position).getTypeInfo().getTypeNo();
        String GenreID = bkfxPaperEntity.getQuesList().get(position).getGenreInfo().getGenreID();

        PostCollectionJson postCollectionJson =new PostCollectionJson();
        postCollectionJson.setKey(UserInfoBean.Key);
        postCollectionJson.setCourseClassID(UserInfoBean.CourseClassID);
        postCollectionJson.setFlag(collectionFlag);
        postCollectionJson.setGenreID(GenreID);
        postCollectionJson.setGlobalGrade(UserInfoBean.GlobalGrade);
        postCollectionJson.setQuesBrief(QuesBreaf);
        postCollectionJson.setQuesID(QuesID);
        postCollectionJson.setTypeNo(TypeNo);
        postCollectionJson.setSchoolID(UserInfoBean.SchoolID);
        postCollectionJson.setStuID(UserInfoBean.StuId);
        postCollectionJson.setSubjectID(UserInfoBean.SubjectID);
        Gson gson=new Gson();
        String BODY= gson.toJson(postCollectionJson);
        Log.e("==BODY=","========BODY====请求参数============="+BODY);
        String BASE_URL = URLConstant.BASE_URL;
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory( GsonConverterFactory.create())
                .build();
        PostCollection_interface postRequest = retrofit.create(PostCollection_interface.class);
        RequestBody body=RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),BODY);
        Call<Integer> call = postRequest.postCollection(body);
        call.enqueue(new Callback<Integer>() {
            @Override
            public void onResponse(Call<Integer> call, Response<Integer> response) {
                String result = response.body().toString();
                Log.e("onResponse=","===============成功=============");
            }

            @Override
            public void onFailure(Call<Integer> call, Throwable t) {
                Log.e("onFailure", t.getMessage());
            }
        });

    }


    //保存作答试题信息
    private void SaveBkfx_KgtQuesAnswer(int position) {
        List<ItemAnswerModel.ModelListBean> ModelList = new ArrayList<>();
        int SubItemAnswerSize = -1;
        String TypeNo = bkfxPaperEntity.getQuesList().get(position).getTypeInfo().getTypeNo();
        List<ItemAnswerModel.ModelListBean.ChildListBean> ChildList = new ArrayList<>();
        if(TypeNo.equals("N")||TypeNo.equals("Q")|| TypeNo.equals("S")||TypeNo.equals("m")||TypeNo.equals("U")){

            List<ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean> SubChildItemList = new ArrayList<>();
            SubItemAnswerSize = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(0).getSubChildList().get(0).getSubChildItem().size();
            for(int i=0;i<SubItemAnswerSize;i++){
                /*****SubChildItem*****************************************************************************/
                String AudioPath = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(0).
                        getSubChildList().get(0).getSubChildItem().get(i).getAudioPath();
                String ImagePath = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(0).
                        getSubChildList().get(0).getSubChildItem().get(i).getImagePath();
                String ItemAnswer = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(0).
                        getSubChildList().get(0).getSubChildItem().get(i).getItemAnswer();
                String StuAnswer = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(0).
                        getSubChildList().get(0).getSubChildItem().get(i).getStuAnswer();
                int ItemIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(0).
                        getSubChildList().get(0).getSubChildItem().get(i).getItemIndex();

                int ScoreRate = -1;
                String[] ItemAnswerArray = LancooUtils.returnArray(ItemAnswer,"$/",2);
                List<String> list=Arrays.asList(ItemAnswerArray);
                if(list.contains(StuAnswer)){
                    ScoreRate = 1;
                }else{
                    ScoreRate = 0;
                }

                ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean subChildItemList
                        = new ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean();
                subChildItemList.setAudioPath(AudioPath);
                subChildItemList.setImagePath(ImagePath);
                subChildItemList.setItemAnswer(ItemAnswer);
                subChildItemList.setStuAnswer(StuAnswer);
                subChildItemList.setItemIndex(ItemIndex);
                subChildItemList.setScoreRate(ScoreRate);
                /**********************************************************************************/
                SubChildItemList.add(subChildItemList);

            }
            /****SubChildList******************************************************************************/
            int SubChildIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(0).getSubChildList().get(0).getSubChildIndex();

            ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean subChildList =
                    new ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean();
            subChildList.setSubChildIndex(SubChildIndex);
            subChildList.setSubChildItem(SubChildItemList);
            /**********************************************************************************/

            /****ChildList******************************************************************************/
            List<ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean> SubChildList = new ArrayList<>();
            int ChildIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(0).getChildIndex();
            SubChildList.add(subChildList);

            ItemAnswerModel.ModelListBean.ChildListBean childList = new ItemAnswerModel.ModelListBean.ChildListBean();
            childList.setChildIndex(ChildIndex);
            childList.setSubChildList(SubChildList);
            ChildList.add(childList);
            /**********************************************************************************/

            /****modelList******************************************************************************/
            double CorrectRate = 0;//需要计算小题准确率，这里先模拟为0
            int AnswerTrue = 0;
            int SubChildListSize = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(0).
                    getSubChildList().get(0).getSubChildItem().size();
            for(int k=0;k<SubChildListSize;k++){
                String ItemAnswerK = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(0).
                        getSubChildList().get(0).getSubChildItem().get(k).getItemAnswer();
                String StuAnswerK = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(0).
                        getSubChildList().get(0).getSubChildItem().get(k).getStuAnswer();

                String[] ItemAnswerArray = LancooUtils.returnArray(ItemAnswerK,"$/",2);
                List<String> list=Arrays.asList(ItemAnswerArray);
                if(list.contains(StuAnswerK)){
                    AnswerTrue = AnswerTrue+1;
                }
            }
            CorrectRate = LancooUtils.getCorrectRate(AnswerTrue,SubChildListSize);
            int lastPaperDuration = bkfxPaperEntity.getDuration();
            int ItemDuration = Integer.valueOf(getChronometerSeconds(mChronometerAnswerTime))-lastPaperDuration;
            String GenreID = bkfxPaperEntity.getQuesList().get(position).getGenreInfo().getGenreID();
            String QuesID = bkfxPaperEntity.getQuesList().get(position).getQuesID();

            ItemAnswerModel.ModelListBean modelList = new ItemAnswerModel.ModelListBean();
            modelList.setCorrectRate(CorrectRate);
            modelList.setDuration(ItemDuration);
            modelList.setGenreID(GenreID);
            modelList.setQuesID(QuesID);
            modelList.setTypeNo(TypeNo);
            modelList.setChildList(ChildList);
            /**********************************************************************************/
            ModelList.add(modelList);
        }else{
            SubItemAnswerSize = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().size();
            for(int i=0;i<SubItemAnswerSize;i++){
                List<ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean> SubChildItemList = new ArrayList<>();
                /*****SubChildItem*****************************************************************************/
                String AudioPath = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).
                        getSubChildList().get(0).getSubChildItem().get(0).getAudioPath();
                String ImagePath = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).
                        getSubChildList().get(0).getSubChildItem().get(0).getImagePath();
                String ItemAnswer = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).
                        getSubChildList().get(0).getSubChildItem().get(0).getItemAnswer();
                String StuAnswer = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).
                        getSubChildList().get(0).getSubChildItem().get(0).getStuAnswer();
                int ItemIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).
                        getSubChildList().get(0).getSubChildItem().get(0).getItemIndex();

                int ScoreRate = -1;
                String[] ItemAnswerArray = LancooUtils.returnArray(ItemAnswer,"$/",2);
                List<String> list=Arrays.asList(ItemAnswerArray);
                if(list.contains(StuAnswer)){
                    ScoreRate = 1;
                }else{
                    ScoreRate = 0;
                }

                ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean subChildItemList
                        = new ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean();
                subChildItemList.setAudioPath(AudioPath);
                subChildItemList.setImagePath(ImagePath);
                subChildItemList.setItemAnswer(ItemAnswer);
                subChildItemList.setStuAnswer(StuAnswer);
                subChildItemList.setItemIndex(ItemIndex);
                subChildItemList.setScoreRate(ScoreRate);
                /**********************************************************************************/

                /****SubChildList******************************************************************************/
                int SubChildIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).getSubChildList().get(0).getSubChildIndex();
                SubChildItemList.add(subChildItemList);

                ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean subChildList =
                        new ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean();
                subChildList.setSubChildIndex(SubChildIndex);
                subChildList.setSubChildItem(SubChildItemList);
                /**********************************************************************************/

                /****ChildList******************************************************************************/
                List<ItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean> SubChildList = new ArrayList<>();
                int ChildIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).getChildIndex();
                SubChildList.add(subChildList);

                ItemAnswerModel.ModelListBean.ChildListBean childList = new ItemAnswerModel.ModelListBean.ChildListBean();
                childList.setChildIndex(ChildIndex);
                childList.setSubChildList(SubChildList);
                ChildList.add(childList);
                /**********************************************************************************/
            }

            /****modelList******************************************************************************/
            double CorrectRate = 0;//需要计算小题准确率，这里先模拟为0
            int AnswerTrue = 0;
            int ChildListSize = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().size();
            for(int k=0;k<ChildListSize;k++){
                String ItemAnswerK = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(k).
                        getSubChildList().get(0).getSubChildItem().get(0).getItemAnswer();
                String StuAnswerK = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(k).
                        getSubChildList().get(0).getSubChildItem().get(0).getStuAnswer();

                String[] ItemAnswerArray = LancooUtils.returnArray(ItemAnswerK,"$/",2);
                List<String> list=Arrays.asList(ItemAnswerArray);
                if(list.contains(StuAnswerK)){
                    AnswerTrue = AnswerTrue+1;
                }
            }
            CorrectRate = LancooUtils.getCorrectRate(AnswerTrue,ChildListSize);
            int lastPaperDuration = bkfxPaperEntity.getDuration();
            int ItemDuration = Integer.valueOf(getChronometerSeconds(mChronometerAnswerTime))-lastPaperDuration;
            String GenreID = bkfxPaperEntity.getQuesList().get(position).getGenreInfo().getGenreID();
            String QuesID = bkfxPaperEntity.getQuesList().get(position).getQuesID();
            String TyoeNo = bkfxPaperEntity.getQuesList().get(position).getTypeInfo().getTypeNo();

            ItemAnswerModel.ModelListBean modelList = new ItemAnswerModel.ModelListBean();
            modelList.setCorrectRate(CorrectRate);
            modelList.setDuration(ItemDuration);
            modelList.setGenreID(GenreID);
            modelList.setQuesID(QuesID);
            modelList.setTypeNo(TypeNo);
            modelList.setChildList(ChildList);
            /**********************************************************************************/
            ModelList.add(modelList);
        }

        ItemAnswerModel itemAnswerModel =new ItemAnswerModel();
        itemAnswerModel.setSubjectID(UserInfoBean.SubjectID);
        itemAnswerModel.setCourseClassID(UserInfoBean.CourseClassID);
        itemAnswerModel.setPaperID(bkfxPaperEntity.getPaperID());
        int PaperDuration = Integer.valueOf(getChronometerSeconds(mChronometerAnswerTime));
        itemAnswerModel.setPaperDuration(PaperDuration);
        itemAnswerModel.setGlobalGrade(UserInfoBean.GlobalGrade);
        itemAnswerModel.setStuID(UserInfoBean.StuId);
        itemAnswerModel.setSchoolID(UserInfoBean.SchoolID);
        itemAnswerModel.setModelList(ModelList);
        itemAnswerModel.setKey(UserInfoBean.Key);

        Gson gson=new Gson();
        String BODY= gson.toJson(itemAnswerModel);
        Log.e("==BODYAA=","========BODY====请求参数=====AAAAA=============="+BODY);
        String BASE_URL = URLConstant.BASE_URL;
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory( GsonConverterFactory.create())
                .build();
        PostSaveItemQuesAnswer_interface postRequest = retrofit.create(PostSaveItemQuesAnswer_interface.class);
        RequestBody body=RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),BODY);
        Call<String> call = postRequest.saveItemQuesAnswer(body);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                Log.e("onResponse=","===============成功============="+response.body().toString());
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                Log.e("onFailure", t.getMessage());
            }
        });

    }

    //保存大数据评阅作答信息
    private void SaveBkfx_ZgtQuesAnswer(final int position) {

        String TypeNo = bkfxPaperEntity.getQuesList().get(position).getTypeInfo().getTypeNo();
        List<SubjectiveItemAnswerModel.ModelListBean> ModelList = new ArrayList<>();
         if(TypeNo.equals("V")||TypeNo.equals("X")||TypeNo.equals("d")||TypeNo.equals("g")){

             List<SubjectiveItemAnswerModel.ModelListBean.ChildListBean> ChildList = new ArrayList<>();
             int ChildListSize = bkfxPaperEntity.getQuesList().get(currentPageIndex).getChildList().size();
             for(int i=0;i<ChildListSize;i++) {
                 SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean subChildItemBean =
                         new SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean();
                 String AudioPath = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                         get(i).getSubChildList().get(0).getSubChildItem().get(0).getAudioPath();
                 String ImagePath = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                         get(i).getSubChildList().get(0).getSubChildItem().get(0).getImagePath();
                 String ItemAnswer = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                         get(i).getSubChildList().get(0).getSubChildItem().get(0).getItemAnswer();
                 int ItemIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                         get(i).getSubChildList().get(0).getSubChildItem().get(0).getItemIndex();
                 String StuAnswer = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                         get(i).getSubChildList().get(0).getSubChildItem().get(0).getStuAnswer();
                 subChildItemBean.setAudioPath(AudioPath);
                 subChildItemBean.setImagePath(ImagePath);
                 subChildItemBean.setItemAnswer(ItemAnswer);
                 subChildItemBean.setItemIndex(ItemIndex);
                 subChildItemBean.setScoreRate(0);
                 subChildItemBean.setStuAnswer(StuAnswer);
                 List<SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean> SubChildItem = new ArrayList<>();
                 SubChildItem.add(subChildItemBean);

                 SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean subChildListBean =
                         new SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean();
                 int SubChildIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).
                         getSubChildList().get(0).getSubChildIndex();
                 subChildListBean.setSubChildIndex(SubChildIndex);
                 subChildListBean.setSubChildItem(SubChildItem);
                 List<SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean> SubChildList = new ArrayList<>();
                 SubChildList.add(subChildListBean);

                 SubjectiveItemAnswerModel.ModelListBean.ChildListBean childListBean =
                         new SubjectiveItemAnswerModel.ModelListBean.ChildListBean();
                 int ChildIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).getChildIndex();
                 childListBean.setChildIndex(ChildIndex);
                 childListBean.setSubChildList(SubChildList);

                 ChildList.add(childListBean);

             }



             SubjectiveItemAnswerModel.ModelListBean modelListBean = new SubjectiveItemAnswerModel.ModelListBean();
             String GenreID = bkfxPaperEntity.getQuesList().get(position).getGenreInfo().getGenreID();
             String QuesID = bkfxPaperEntity.getQuesList().get(position).getQuesID();
             modelListBean.setCorrectRate(0);//待传
             modelListBean.setDuration(0);//待传
             modelListBean.setGenreID(GenreID);
             modelListBean.setQuesID(QuesID);
             modelListBean.setTypeNo(TypeNo);
             modelListBean.setChildList(ChildList);
             ModelList.add(modelListBean);

         }else if(TypeNo.equals("b")||TypeNo.equals("k")){
             List<SubjectiveItemAnswerModel.ModelListBean.ChildListBean> ChildList = new ArrayList<>();
             int ChildListSize = bkfxPaperEntity.getQuesList().get(currentPageIndex).getChildList().size();
             for(int i=0;i<ChildListSize;i++) {

                 List<SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean> SubChildItem = new ArrayList<>();
                 int SubChildItemSize = bkfxPaperEntity.getQuesList().get(currentPageIndex).getChildList().
                         get(i).getSubChildList().get(0).getSubChildItem().size();
                 for(int j=0;j<SubChildItemSize;j++){
                     SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean subChildItemBean =
                             new SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean.SubChildItemBean();
                     String AudioPath = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                             get(i).getSubChildList().get(0).getSubChildItem().get(j).getAudioPath();
                     String ImagePath = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                             get(i).getSubChildList().get(0).getSubChildItem().get(j).getImagePath();
                     String ItemAnswer = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                             get(i).getSubChildList().get(0).getSubChildItem().get(j).getItemAnswer();
                     int ItemIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                             get(i).getSubChildList().get(0).getSubChildItem().get(j).getItemIndex();
                     String StuAnswer = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                             get(i).getSubChildList().get(0).getSubChildItem().get(j).getStuAnswer();

                     double ScoreRate = 0;
                     if(TypeNo.equals("k")) {
                         int ChildAnswerType = bkfxPaperEntity.getQuesList().get(position).getChildList().
                                 get(i).getChildAnswerType();
                         if(ChildAnswerType!=4) {
                             String[] ItemAnswerArray = LancooUtils.returnArray(ItemAnswer, "$/", 2);
                             List<String> list = Arrays.asList(ItemAnswerArray);
                             if (list.contains(StuAnswer)) {
                                 ScoreRate = 1;
                             }
                         }
                     }

                     subChildItemBean.setAudioPath(AudioPath);
                     subChildItemBean.setImagePath(ImagePath);
                     subChildItemBean.setItemAnswer(ItemAnswer);
                     subChildItemBean.setItemIndex(ItemIndex);
                     subChildItemBean.setScoreRate(ScoreRate);
                     subChildItemBean.setStuAnswer(StuAnswer);

                     SubChildItem.add(subChildItemBean);
                 }


                 SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean subChildListBean =
                         new SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean();
                 int SubChildIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).
                         getSubChildList().get(0).getSubChildIndex();
                 subChildListBean.setSubChildIndex(SubChildIndex);
                 subChildListBean.setSubChildItem(SubChildItem);
                 List<SubjectiveItemAnswerModel.ModelListBean.ChildListBean.SubChildListBean> SubChildList = new ArrayList<>();
                 SubChildList.add(subChildListBean);

                 SubjectiveItemAnswerModel.ModelListBean.ChildListBean childListBean =
                         new SubjectiveItemAnswerModel.ModelListBean.ChildListBean();
                 int ChildIndex = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).getChildIndex();
                 childListBean.setChildIndex(ChildIndex);
                 childListBean.setSubChildList(SubChildList);

                 ChildList.add(childListBean);

             }



             SubjectiveItemAnswerModel.ModelListBean modelListBean = new SubjectiveItemAnswerModel.ModelListBean();
             String GenreID = bkfxPaperEntity.getQuesList().get(position).getGenreInfo().getGenreID();
             String QuesID = bkfxPaperEntity.getQuesList().get(position).getQuesID();
             modelListBean.setCorrectRate(0);//待传
             modelListBean.setDuration(0);//待传
             modelListBean.setGenreID(GenreID);
             modelListBean.setQuesID(QuesID);
             modelListBean.setTypeNo(TypeNo);
             modelListBean.setChildList(ChildList);
             ModelList.add(modelListBean);
         }


        SubjectiveItemAnswerModel subjectiveItemAnswerModel = new SubjectiveItemAnswerModel();
        subjectiveItemAnswerModel.setCourseClassID(UserInfoBean.CourseClassID);
        subjectiveItemAnswerModel.setGlobalGrade(UserInfoBean.GlobalGrade);
        subjectiveItemAnswerModel.setKey(UserInfoBean.Key);
        int PaperDuration = Integer.valueOf(getChronometerSeconds(mChronometerAnswerTime));
        subjectiveItemAnswerModel.setPaperDuration(PaperDuration);
        subjectiveItemAnswerModel.setStuID(UserInfoBean.StuId);
        subjectiveItemAnswerModel.setSchoolID(UserInfoBean.SchoolID);
        subjectiveItemAnswerModel.setSubjectID(UserInfoBean.SubjectID);
        subjectiveItemAnswerModel.setPaperID(bkfxPaperEntity.getPaperID());
        subjectiveItemAnswerModel.setModelList(ModelList);

        Gson gson=new Gson();
        String BODY= gson.toJson(subjectiveItemAnswerModel);
        Log.e("==BODYAA=","========BODY====请求参数=====AAAAA=============="+BODY);
        String BASE_URL = URLConstant.BASE_URL;
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory( GsonConverterFactory.create())
                .build();
        PostSaveSubjectiveItemQuesAnswer_interface postRequest = retrofit.create(PostSaveSubjectiveItemQuesAnswer_interface.class);
        RequestBody body=RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),BODY);
        Call<List<ResultSubjectiveItemJson>> call = postRequest.saveSubjectiveItemQuesAnswer(body);
        call.enqueue(new Callback<List<ResultSubjectiveItemJson>>() {
            @Override
            public void onResponse(Call<List<ResultSubjectiveItemJson>> call, Response<List<ResultSubjectiveItemJson>> response) {
                Log.e("onResponse=","===============成功============="+response.body().toString());

                if(!isSubmitOrExitAlready){
                    String TypeNo = bkfxPaperEntity.getQuesList().get(position).getTypeInfo().getTypeNo();
                    int Size = bkfxPaperEntity.getQuesList().get(position).getChildList().size();
                    for(int i=0;i<Size;i++){
                        double ScoreRate = response.body().get(i).getScoreRate();
                        if(TypeNo.equals("b")){
                            bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                                    get(0).getSubChildList().get(0).getSubChildItem().get(i).setScoreRate(ScoreRate);
                        }else if(TypeNo.equals("k")){
                            int ChildAnswerType = bkfxPaperEntity.getQuesList().get(position).getChildList().get(i).getChildAnswerType();
                            if(ChildAnswerType==4){
                                //简答
                                double ScoreRate_jd = response.body().get(i).getScoreRate();
                                bkfxPaperEntity.getPaperAnswer().get(position).getChildList().get(i).getSubChildList().get(0).getSubChildItem().get(0).setScoreRate(ScoreRate_jd);
                            }else if(ChildAnswerType==2){
                                //填空
                                int Size_tk = bkfxPaperEntity.getQuesList().get(position).getChildList().get(i).getSubChildList().get(0).getSubChildItem().size();
                                for(int j=0;j<Size_tk;j++){
                                    String ItemAnswer = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                                            get(i).getSubChildList().get(0).getSubChildItem().get(j).getItemAnswer();
                                    String StuAnswer = bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                                            get(i).getSubChildList().get(0).getSubChildItem().get(j).getStuAnswer();
                                    double ScoreRate_tk = 0;
                                    String[] ItemAnswerArray = LancooUtils.returnArray(ItemAnswer,"$/",2);
                                    List<String> list=Arrays.asList(ItemAnswerArray);
                                    if(list.contains(StuAnswer)){
                                        ScoreRate = 1;
                                    }
                                    bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                                            get(i).getSubChildList().get(0).getSubChildItem().get(j).setScoreRate(ScoreRate_tk);

                                    double EachScore = -1;
                                    String QuesList_QuesID = bkfxPaperEntity.getQuesList().get(position).getQuesID();
                                    int QuesPaperSize = bkfxPaperEntity.getPaperQues().size();
                                    for(int k=0;k<QuesPaperSize;k++){
                                        int QuesPaperQuesListSize = bkfxPaperEntity.getPaperQues().get(k).getQuesList().size();
                                        for(int p=0;p<QuesPaperQuesListSize;p++){
                                            String QuesPaper_QuesID = bkfxPaperEntity.getPaperQues().get(k).getQuesList().get(p).getQuesID();
                                            if(QuesList_QuesID.equals(QuesPaper_QuesID)){
                                                EachScore =  bkfxPaperEntity.getPaperQues().get(k).getEachScore();
                                                break;
                                            }
                                        }
                                    }
                                }

                            }else if(ChildAnswerType==1){
                                //选择
                            }
                        }else {
                            bkfxPaperEntity.getPaperAnswer().get(position).getChildList().
                                    get(i).getSubChildList().get(0).getSubChildItem().get(0).setScoreRate(ScoreRate);
                        }
                    }

                    if(TypeNo.equals("k")){
                        BkfxYdzhFragment fragment = (BkfxYdzhFragment) mFragmentList.get(position);
                        //显示刷新作答结果
                        ArrayList<View> list = new ArrayList<>();
                        list.clear();
                        int ChildListSize = bkfxPaperEntity.getQuesList().get(position).getChildList().size();
                        for (int i = 0; i < ChildListSize; i++) {
                            RecyclerView mRvAnswer = new RecyclerView(BkfxActivity.this);
                            mRvAnswer.setLayoutManager(new LinearLayoutManager(BkfxActivity.this));//必须先设置LayoutManager

                            int ChildAnswerType = bkfxPaperEntity.getQuesList().get(position).getChildList().get(i).getChildAnswerType();
                            if(ChildAnswerType==4){
                                //简答
                                BkfxYdzhAnswerAdapter_jd mAnswerAdapter = new BkfxYdzhAnswerAdapter_jd(BkfxActivity.this,
                                        bkfxPaperEntity,position,i,new BkfxYdzhAnswerAdapter_jd.CallBackAdapterYdzh_jd() {
                                    @Override
                                    public void callHideRecordMiView() {

                                    }

                                    @Override
                                    public void callRefreshClickAnswer() {
                                    }

                                    @Override
                                    public void callSubmitRefreshView() {

                                    }

                                });
                                mRvAnswer.setAdapter(mAnswerAdapter);
                            }else if(ChildAnswerType==2){

                                //填空
                                BkfxYdzhAnswerAdapter_tk mAnswerAdapter = new BkfxYdzhAnswerAdapter_tk(BkfxActivity.this, bkfxPaperEntity, position,i);
                                mAnswerAdapter.setHasStableIds(true);
                                mRvAnswer.setAdapter(mAnswerAdapter);
                                int SubChildItemSize = bkfxPaperEntity.getQuesList().get(position).
                                        getChildList().get(i).getSubChildList().get(0).getSubChildItem().size();
                                mRvAnswer.setItemViewCacheSize(SubChildItemSize);
//                }

                            }else if(ChildAnswerType==1){
                                //选择

                            }

                            list.add(mRvAnswer);
                        }

                        ViewPager mVpAnswer = fragment.getView().findViewById(R.id.vp_answerYdzh);
                        mVpAnswer.setAdapter(new AnswerViewPagerAdapter(list));
                        Log.e("==jjjj==","===JJJJ===="+bkfxPaperEntity.getPaperAnswer().get(position).getCurrentSubChildAnswerIndex());
                        mVpAnswer.setCurrentItem( bkfxPaperEntity.getPaperAnswer().get(position).getCurrentSubChildAnswerIndex());

                    }else if(TypeNo.equals("b")||TypeNo.equals("d")||TypeNo.equals("X")
                            ||TypeNo.equals("g")||TypeNo.equals("V")){
                        BkfxYdjdFragment fragment = (BkfxYdjdFragment) mFragmentList.get(position);
                        Button mBtnSubmit = fragment.getView().findViewById(R.id.btn_submit);
                        mBtnSubmit.setVisibility(View.GONE);
                        //显示刷新作答结果
                        ArrayList<View> list = new ArrayList<>();
                        list.clear();
                        int totalItemCount = bkfxPaperEntity.getQuesList().get(position).getTotalItemCount();
                        for(int i=0;i<totalItemCount;i++) {
                            final RecyclerView mRvAnswer = new RecyclerView(BkfxActivity.this);
                            mRvAnswer.setLayoutManager(new LinearLayoutManager(BkfxActivity.this));//必须先设置LayoutManager
                            BkfxYdjdAnswerAdapter mAnswerAdapter = new BkfxYdjdAnswerAdapter(BkfxActivity.this,
                                    bkfxPaperEntity,position,i);
                            mRvAnswer.setAdapter(mAnswerAdapter);
                            list.add(mRvAnswer);
                        }
                        ViewPager mVpAnswer = fragment.getView().findViewById(R.id.vp_answerYdjd);
                        mVpAnswer.setAdapter(new AnswerViewPagerAdapter(list));
                        Log.e("==jjjj==","===JJJJ===="+bkfxPaperEntity.getPaperAnswer().get(position).getCurrentSubChildAnswerIndex());
                        mVpAnswer.setCurrentItem( bkfxPaperEntity.getPaperAnswer().get(position).getCurrentSubChildAnswerIndex());

                    }

                    if(mLlJudegLoading[position]!=null) {
                        mLlJudegLoading[position].setVisibility(View.GONE);
                    }
                }

            }

            @Override
            public void onFailure(Call<List<ResultSubjectiveItemJson>> call, Throwable t) {
                Log.e("onFailure", t.getMessage());
            }
        });

    }

    //提交整份试卷作答
    private void SubmitPaper() {

        bkfxPaperEntity.setState(2);

        List<ItemAnswerModel.ModelListBean> ModelList = new ArrayList<>();
        ItemAnswerModel itemAnswerModel =new ItemAnswerModel();
        itemAnswerModel.setSubjectID(UserInfoBean.SubjectID);
        itemAnswerModel.setCourseClassID(UserInfoBean.CourseClassID);
        itemAnswerModel.setPaperID(PaperId);
        int PaperDuration = Integer.valueOf(getChronometerSeconds(mChronometerAnswerTime));
        itemAnswerModel.setPaperDuration(PaperDuration);
        itemAnswerModel.setGlobalGrade(UserInfoBean.GlobalGrade);
        itemAnswerModel.setStuID(UserInfoBean.StuId);
        itemAnswerModel.setSchoolID(UserInfoBean.SchoolID);
        itemAnswerModel.setModelList(ModelList);
        itemAnswerModel.setKey(UserInfoBean.Key);

        Gson gson=new Gson();
        String BODY= gson.toJson(itemAnswerModel);
        Log.e("==BODYAA=","========BODY====请求参数=====AAAAA=============="+BODY);
        String BASE_URL = URLConstant.BASE_URL;
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory( GsonConverterFactory.create())
                .build();
        PostSubmitPaper_interface postRequest = retrofit.create(PostSubmitPaper_interface.class);
        RequestBody body=RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),BODY);
        Call<String> call = postRequest.submitPaper(body);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                Log.e("onResponse=","===============成功============="+response.body().toString());
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                Log.e("onFailure", t.getMessage());
            }
        });

    }

}